/**
 * @file
 * @auth jinguangguo
 * @date 2016/10/21
 */

import gulp from 'gulp';
import scp2 from 'gulp-scp2';
// const SERVER_HOST_TEST = '172.16.33.230';
// const PORT = 9422;
// const USERNAME = 'appuser';
// const PASSWORD = 'jk6E%z5fg33221EE';

// ============= http://gdae2.dev.gpdax.com/ ============
const SERVER_HOST_TEST = '172.16.33.231';
const PORT = 9422;
const USERNAME = 'root';
const PASSWORD = '123456';

gulp.task('scp:dev', ['dev'], () => {
    // 对应地址: http://www.dev.gpdax.com
    return gulp.src('./dev/**/*')
        .pipe(scp2({
            host: SERVER_HOST_TEST,
            port: PORT,
            username: USERNAME,
            password: PASSWORD,
            dest: '/data/app/static/exchange_news',
            watch(client) {
                client.on('write', function(o) {
                    global.logger.info('write ' + o.destination);
                });
                client.on('end', function(o) {
                    global.logger.warn(`[scp file upload ok...`);
                });
            }
        }))
        .on('error', function(err) {
            logger.error(err);
        });
});

gulp.task('scp:qa', ['dev'], () => {

    let options = {
        host: '118.190.102.210',  //121.42.41.192
        port: '19422',
        user: 'appuser',
        pass: 'I6(K#ICPi(ra',
        remotePath: '/data/app/static/exchangeApi'
    };

    return gulp.src('./dev/**/*')
        .pipe(scp2({
            host: options.host,
            port: options.port,
            username: options.user,
            password: options.pass,
            dest: options.remotePath,
            watch(client) {
                client.on('write', function(o) {
                    global.logger.info('write ' + o.destination);
                });
                client.on('end', function(o) {
                    global.logger.warn(`[scp file upload ok...`);
                });
            }
        }))
        .on('error', function(err) {
            logger.error(err);
        });
});

gulp.task('scp:prod', ['prod'], () => {
    return gulp.src('./prod/**/*')
        .pipe(scp2({
            host: SERVER_HOST_TEST,
            port: PORT,
            username: USERNAME,
            password: PASSWORD,
            dest: '/data/app/static/exchange_news',
            watch(client) {
                client.on('write', function(o) {
                    global.logger.info('write ' + o.destination);
                });
                client.on('end', function(o) {
                    global.logger.warn(`[scp file upload ok...`);
                });
            }
        }))
        .on('error', function(err) {
            logger.error(err);
        });
});